﻿using System.Diagnostics;
using System.IO;
using System.IO.IsolatedStorage;
using System.Reflection;

namespace Borg.Framework
{
    public abstract class CompositionPersistor
    {
        protected Composer composer = null;
        protected static IsolatedStorageFile store = GetStore();
        protected const string VERSION1 = "Borg Compilation Version 0.1.3.0";

        public static void DeleteFile(string filename)
        {
            store.DeleteFile(filename);
        }

        protected static IsolatedStorageFile GetStore()
        {
            return IsolatedStorageFile.GetStore(
                IsolatedStorageScope.Assembly | IsolatedStorageScope.User, null, null);
        }

        public static void OpenFileLocation()
        {
            var stream = new IsolatedStorageFileStream("temp", FileMode.Create, store);
            
            string str = stream.GetType().GetField("m_FullPath",
                BindingFlags.NonPublic | BindingFlags.Instance).GetValue(stream).ToString();
            
            stream.Close();
            store.DeleteFile("temp");

            Process.Start("explorer", str.Substring(0, str.LastIndexOf('\\') + 1));
        }
    }
}

